<?php 

if ( !current_user_can('publish_posts')) {
	 echo 'ingen tilgang.';
	} 
        else {
?>


<?php

 global $hide_right_sidebar;
$hide_right_sidebar = true;
    
//----------brukt info fra http://voodoopress.com/how-to-post-from-your-front-end-with-no-plugin/
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {
 
    // Do some minor form validation to make sure there is content
    if(!isset($_POST['title']) || !isset($_POST['description']) ) {
        if(!isset($_POST['title'])) 
            echo 'Du glemte nyhetens tittel';
        
        if (!isset($_POST['description']))
            echo 'Du glemte å skrive noe om den';
        
        echo '';
    } else {
        $title =  $_POST['title'];
        $description = $_POST['description'];
    }
  
 
    $tags = $_POST['post_tags'];
 
    // ADD THE FORM INPUT TO $new_post ARRAY
    $new_post = array(
    'post_title'    =>   $title,
    'post_content'  =>   $description,
    'post_category' =>   array($_POST['cat']),  // Usable for custom taxonomies too
    'tags_input'    =>   array($tags),
    'post_status'   =>   'publish',           // Choose: publish, preview, future, draft, etc.
    'post_type' =>   'post'  //'post',page' or use a custom post type if you want to
    );
 
    //SAVE THE POST
    $pid = wp_insert_post($new_post);
 
             //SET OUR TAGS UP PROPERLY
    wp_set_post_tags($pid, $_POST['post_tags']);
 
    //REDIRECT TO THE NEW POST ON SAVE
    $link = get_permalink($pid);
    echo $link;
    wp_redirect($link);
    exit();
    
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
//POST THE POST YO
do_action('wp_insert_post', 'wp_insert_post');
//--------------------------------

        }
//wp_insert_post($postarr);
 ?>




<form action="" id="new_post" name="new_post" method="POST" enctype="multipart/form-data">
 
    <fieldset name ="name">
        <label for="title"><?php _e('Nyhets tittel:', 'framework') ?></label>
 
        <input type="text" name="title" id="title" class="required" />
    </fieldset>
 
    <fieldset class="content">
        <label for="textarea01"><?php _e('Innhold:', 'framework') ?></label>
        
        <?php  wp_editor('', 'description'); ?>
        <!--<textarea name="postContent" id="postContent" rows="8" cols="30" class="required"></textarea>-->
    </fieldset>
    <fieldset class="category">
        <label for="kategorier"></br>Kategori: </label>
    <?php wp_dropdown_categories( 'show_option_none=Ikke Valgt&tab_index=4&taxonomy=category&hide_empty=0' ); ?>
    </fieldset
    <fieldset class="tags">
        <label for="post_tags">Søkeord for nyheten (separert med komma): </label>
        <input type="test" value="" tabindex="35" name="post_tags" id="post_tags"/>
    </fieldset>
    <fieldset class="submit">
        <input type="hidden" name="submit" id="submit" value="true" />
 
        <button type="submit"  >Legg til nyhet<?php // _e('Add Post', 'framework') ?></button>
    </fieldset>
    <input type="hidden" name="action" value="new_post"/>
    <?php        wp_nonce_field('new_post'); ?>
</form>




